import $api from '@/common/js/api.js'
import {isWxBrower, getUrlQuery,getQuerySourceId} from '@/common/js/utils.js'

let state = {
		userInfo: {} ,//用户信息
		urlCode:"", //URL中的邀请码
		configData:[],//配置信息
	},
	getters = {
	},
	mutations = {
		// 保存登录后用户的信息
		setUserInfo(state, info) {
			state.userInfo = info
		},
		// 清除用户信息
		clearUserInfo(state) {
			state.userInfo = {}
			uni.removeStorageSync("token")
		},
		// 保存URL中的邀请码
		setUrlCode(state, code){
			state.urlCode = code
		},
		// 保存配置信息
		setConfigData(state, data){
			state.configData = data
		}
	},
	actions = {
		//获取用户信息
		async getUserInfo({commit}) {
			let res = await $api.getUserInfo()
			// console.log("获取用户信息", res)
			if (res && res.code === 1 && res.data) {
				commit("setUserInfo", res.data)
			}
		},
		//获取配置信息
		async geConfigData({commit}){
			let res = await $api.getConfigInfo()
			// console.log("配置i细腻",res)
			if(res.code === 1 && res.data){
				commit("setConfigData", res.data)
			}
		}
	}
export default {
	namespaced: true,
	state,
	getters,
	mutations,
	actions
}
